package com.ruibang.glass.equipment.controller;

import com.ruibang.glass.equipment.domain.req.device.PointCheckRwReq;
import com.ruibang.glass.equipment.entity.device.PointCheckRecord;
import com.ruibang.glass.equipment.entity.device.PointCheckRw;
import com.ruibang.glass.equipment.service.PointCheckRecordService;
import com.ruibang.glass.equipment.service.PointCheckRwService;
import com.teaming.cloud.framework2.common.model.ResultBody;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
/**
 * <p>
 *点检任务
 * </p>
 *
 * @author mameng
 * @since 2024-03-20
 */
@RestController
@RequestMapping("/api/equipment/point/check/rw")
@Api(value = "点检任务")
public class PointCheckRwController {
    @Autowired
    private PointCheckRwService pointCheckPlanService;

    @Autowired
    private PointCheckRecordService pointCheckRecordService;

    @PostMapping("list")
    @ApiOperation(value = "获取点检计划列表", response = ResultBody.class)
    public ResultBody getBoilerList(@RequestBody PointCheckRwReq deviceAllPageReq) {
        return ResultBody.success(pointCheckPlanService.getCheckPlanList(deviceAllPageReq));
    }

    @PostMapping("addOrUpdateCheck")
    @ApiOperation(value = "更新编辑", response = ResultBody.class)
    public ResultBody addChild(@RequestBody PointCheckRw pointCheckPlan) {
        return ResultBody.success(pointCheckPlanService.addOrUpdateCheck(pointCheckPlan));
    }


    //
    @GetMapping("deleteAll/{id}")
    @ApiOperation(value = "点检", response = ResultBody.class)
    public ResultBody deleteAll(@PathVariable("id") String id) {
        PointCheckRw pointCheckPlan = pointCheckPlanService.getById(id);
        PointCheckRecord pointCheckRecord = new PointCheckRecord();
        pointCheckRecord.setDeviceName(pointCheckPlan.getDeviceName());
        pointCheckRecord.setInspectionLocation(pointCheckPlan.getPointPart());
        pointCheckRecord.setInspectionTime(pointCheckPlan.getStartTime());
        pointCheckRecord.setInspector(pointCheckPlan.getPointPerson());
        pointCheckRecord.setPlanId(pointCheckPlan.getId());
        pointCheckRecord.setStartTime(new Date());
        pointCheckRecordService.save(pointCheckRecord);
        pointCheckPlanService.updateById(pointCheckPlan);
        return ResultBody.success();
    }


}
